package com.liuwei.classy.dao;


import com.liuwei.classy.model.User;
import org.apache.ibatis.annotations.*;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

/**
 * Created by qingshengzheng on 15/11/18.
 */
@Mapper
@CacheConfig(cacheNames = "user")
public interface UserMapper {
    //新增用户
    @Insert("INSERT INTO user(username, avatar, sex, openid, platform, age, createtime) VALUES(#{user.username}, #{user.avatar}, #{user.sex}, #{user.openid}, #{user.platform}, #{user.age}, #{user.createtime})")
    @Options(useGeneratedKeys = true, keyProperty = "uid")
    public void addUser(@Param("user") User user);
    //修改用户
    public void modfiyUser(User user);
    //根据uid获取user
    @Cacheable(key="'USER_DETAIL:'+#p0+''")
    @Select("SELECT * FROM user WHERE uid = #{uid}")
    public User queryUserByUid(@Param("uid") long uid);
    //重置用户密码
    public void resetPwd(String mobile, String password);
    //根据openid和类型获取用户
    @Cacheable(key="'USER_OPENID:'+#p0+''")
    @Select("SELECT * FROM user WHERE openid = #{openid}")
    public User userDetailByOpenidAndType(@Param("openid") String openid,String type);
}
